import { Injectable } from '@nestjs/common';
import * as COS from 'cos-nodejs-sdk-v5';
import { ConfigService } from '@nestjs/config';
@Injectable()
export class CosService {
  private cos: COS;
  constructor(private readonly configService: ConfigService) {
    this.cos = new COS({
      SecretId: this.configService.get('COS_SECRET_ID'),
      SecretKey: this.configService.get('COS_SECRET_KEY'),
    });
  }
  getAuth(key, expires = 60) {
    const buchet = this.configService.get('COS_BUCHET');
    const region = this.configService.get('COS_REGION');
    const sign = this.cos.getAuth({
      Method: 'put',
      Key: key,
      Expires: expires,
      Bucket: buchet,
      Region: region,
    });
    return {
      sign,
      key,
      buchet,
      region,
    };
  }
}
